package com.miku.blog.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author shkstart
 * @create ${}YEAR-05-26 6:14
 */
public class HttpUtils {

    public static HttpServletRequest getHttpServletRequest(){
        ServletRequestAttributes requestAttributes
                = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return requestAttributes.getRequest();
    }

    public static HttpSession getHttpSession(){
        return getHttpServletRequest().getSession(false);
    }

    public static String getSessionId(){
        return getHttpSession().getId();
    }

}
